package com.lvmama.controller.rhino.system;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lvmama.client.rhino.MenuClient;
import com.lvmama.common.result.Result;
import com.lvmama.pojo.entity.rhino.system.Menu;
import com.lvmama.pojo.entity.rhino.system.User;

@Controller
@Slf4j
public class RhinoController {

	@Autowired
	MenuClient menuClient;

	@RequestMapping(value = { "/index", "/" })
	public String index(Model model, HttpServletRequest request) {
		log.info("index start");

		HttpSession session = request.getSession();
		User currentUser = (User) session.getAttribute("currentUser");
		// 查询出页面的菜单
		Result<List<Menu>> result = menuClient
				.getAllMenuListByUser(currentUser);
		List<Menu> menus = result.getData();
		model.addAttribute("menus", menus);
		model.addAttribute("currentUser", currentUser);
		Boolean isAdmin = currentUser.isAdmin();
		model.addAttribute("isAdmin", isAdmin);

		log.info("index end.");
		return "index";
	}

	@RequestMapping(value = { "/login" })
	public String login() {
		return "/login";
	}

}
